<template>
	<div :fieldrender="field.vModel">
		<div v-show="isShow"> <img field="field.vModel" handsign-field="field.vModel" :src="imgSrcData"
				:width="width" /></div>
		<el-button :field="field.vModel" size="mini" v-if="!isReadOnly" type="primary" title="选择"
			@click="onlineForm_onHandsignDialogClick"><i class="fa fa-edit">手写签名</i></el-button>
	</div>
</template>

<script>
	export default {
		name: "f2bpm-handsign",
		props: ['field', 'fieldvalue'],
		watch: {
			value(val, oleV) {
				var that = this;
				if (val != undefined && oleV != undefined && f2grid_global_mainVueLoadComplated) {
					this.$emit('updatevalue', that.field, val);
				}
			},
			fieldvalue: {
				handler(newV, oleV) {
					var that = this;
					if (newV != undefined && oleV != undefined && f2grid_global_mainVueLoadComplated) {
						that.value = newV;
					}
				},
				immediate: false
			}
		},
		created: function() {
			var that = this;
			that.value = that.fieldvalue;
			var formAction = WFContext.WorkflowformAction;
			that.isView = formAction > 2;
			if (that.isView) {
				that.isReadOnly = true;
			} else if (that.field._isReadOnly == true) {
				that.isReadOnly = true;
			}
			if (that.field.inputCtrlOption) {
				var json = typeof that.field.inputCtrlOption == "object" ? that.field.inputCtrlOption : eval("(" + that
					.field.inputCtrlOption +
					")");
				that.inputCtrlOption = json;
				that.prefix = that.inputCtrlOption.showPathPrefix;
			}
			var width = that.field.width || 250;
			if (width == 0) {
				width = 250;
			}
			that.width = width + "px";
			if (that.value) {
				that.onlineForm_loadSign();
			}
		},
		mounted() {
			var that = this;
			//FUI.F2Grid.excuteFieldWritePowerByVueFormItem(that);
		},
		data: function() {
			return {
				isView: false,
				//是否为只读
				isReadOnly: false,
				isShow: true,
				width: '',
				prefix: '',
				inputCtrlOption: null,
				imgSrcData: null,
				value: '',
			}
		},
		methods: {
			onlineForm_onHandsignDialogClick() {
				if (WFContext.isDesign == true) {
					return false;
				}
				var that = this;
				var optionJson = that.inputCtrlOption;
				var isreSign = 1;
				var signId = that.value || "";
				if (signId == "" || signId == undefined) {
					signId = Object.toGuid();
					isreSign = 0;
				}
				//打开二维码的对话框
				var wiid = WFContext.WorkflowInstanceId;
				var creatorId = WFContext.UserId;
				var url = __webpath + "/workflow/selector/handsign/?isreSign=" + isreSign +
					"&linkType=wiid&linkEntityId=" + wiid + "&creatorId=" + creatorId + "&signId=" + signId;
				var title = "扫一扫手写签名二维码";
				FUI.dialog(url, title, {}, 400, 450, function(signId, index, layer) {
					that.value = signId;
					that.onlineForm_loadSign();
					//获取签名图片数据，显示表单签名图片
					layer.close(index);
					return false;
				}, false, {
					fit: true
				}, {
					sure: {
						text: '确认签名'
					}
				});
			},
			onlineForm_loadSign() {
				var that = this;
				var signId = that.value;
				var data = Object.toAjaxJson("/workflow/public/", "getHandSignData", {
					"signId": signId
				});
				if (data.success) {
					that.imgSrcData = data.data.imgData;
					this.isShow = true;
				}
				if (that.imgSrcData != '') {
					that.isShow = true;
				} else {
					that.isShow = false;
				}
			}

		}
	};
</script>
